#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
	int m = 0, n = 0;
	cin >> m >> n;
	if (m == 0)
	{
		cout << 0;
		return 0;
	}
	string ret = "", str = "0123456789ABCDEF";
	bool flag = false;
	if (m < 0)
	{
		m = -m;
		flag = true;
	}
	while (m > 0)
	{
		ret += str[m % n];
		m /= n;
	}
	if (flag)
		ret += '-';
	reverse(ret.begin(), ret.end());
	cout << ret;
	return 0;
}